/**
 * Copyright(C) 2018 Fugle Technology Co., Ltd. All rights reserved.
 */
package com.ifugle.rap.application.controller;

import java.util.ArrayList;
import java.util.List;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import com.ifugle.rap.application.model.Message;
import com.ifugle.rap.application.model.Product;
import com.ifugle.rap.application.service.PayService;
import com.ifugle.rap.application.service.ProductService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.converter.json.MappingJacksonValue;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

/**
 *
 * @author HuangLei(wenyuan)
 * @version $Id PayController.java v 0.1 2018/8/7 HuangLei(wenyuan) Exp $
 */
@RestController
@RequestMapping("/H5Agent")
public class PayController {

    @Autowired
    ProductService productService;

    @RequestMapping(value = "Fee", method = RequestMethod.GET)
    @ResponseBody
    public Object fee(String callback,String NType,String appId,HttpServletRequest request,HttpServletResponse response) {
        Object result=null;
        if(StringUtils.isBlank(callback)){
            return result;
        }

        if(StringUtils.equals("get_recharge_list",NType)){//获取充值产品列表
            List<Product> list = productService.selectByList();
            result= list;
        }else if(StringUtils.equals("pay_confirm",NType)){//支付确认
            String confirmId = request.getParameter("confirmId");
            String answer = request.getParameter("answer");
            Message message =  new Message();
            message.setStatus("100000");
            message.setMessage("success");
            result= message;

        }else if(StringUtils.equals("get_recharge_image",NType)){//获取充值验证码
            String cpId = request.getParameter("cpId");
            String cpServiceId = request.getParameter("cpServiceId");
            String feeCode = request.getParameter("feeCode");
            String channelId = request.getParameter("channelId");
            String userId = request.getParameter("userId");
            Message message =  new Message();
            message.setStatus("100000");
            message.setMessage("success");
            message.setObject("10000001");
            result= message;

        }else if(StringUtils.equals("register",NType)){//注册移动平台
            String cpId = request.getParameter("cpId");
            String cpServiceId = request.getParameter("cpServiceId");
            String channelId = request.getParameter("channelId");
            String userId = request.getParameter("userId");
            Message message =  new Message();
            message.setStatus("0");
            message.setMessage("success");
            result= message;
        }
        MappingJacksonValue mappingJacksonValue = new MappingJacksonValue(result);
        mappingJacksonValue.setJsonpFunction(callback);
        return mappingJacksonValue;
    }


}
